var data = null
var count = 0 //级数
var sjson = 0 //json++
var sloa = 0 //loca++
var josnss = 0 //判断是否是json信息
var locations = 0 //判断是否为location文件
console.log("   asd")
var a = 1 //确定导航栏

function manage() {
    count = 0
    sjson = 0
    locations = 0
    josnss = 0
    var btn = document.getElementById('btn')
        // for (var j = 0; j < localStorage.length; j++) {
        //     console.log(
        //         'localStorage里存储的第' +
        //         j +
        //         '条数据的名字为：' +
        //         localStorage.key(j) +
        //         ',值为：' +
        //         localStorage.getItem(localStorage.key(j)));
        // }
    btn.onclick = function() {
        console.log("aas")


        // console.log(data[i])
        var user = document.getElementById('user')
        var psd = document.getElementById('psd')
        if (sjson == 0) {
            // console.log("sjson == 0")

            for (let i = 0; i < data.length; i++) {
                if (user.value == data[i].name) {
                    count++
                    console.log("JSON判断名字")
                    console.log("json" + count)
                    josnss++
                    sjson++
                    break
                }
            }
        }
        if (sjson == 0) {
            // console.log("localStorage.length" + localStorage.length)
            for (let s = 0; s < localStorage.length; s++) {
                console.log("localStorage.length：：" + localStorage.key(s))

                if (user.value == localStorage.key(s)) {
                    count++
                    console.log("location判断名字")
                    console.log("location判断名字" + count)
                    locations++
                    break
                }

            }
        }


        if (count == 1) {
            for (let i = 0; i < data.length; i++) {
                if (psd.value == data[i].password) {
                    count++
                    console.log("JSON判端密码")
                    console.log("json" + count)
                    josnss++
                    break
                }
            }

        }
        if (count == 1) {
            for (let ss = 0; ss < localStorage.length; ss++) {
                console.log("locapassword")
                if (psd.value == localStorage.getItem(localStorage.key(ss))) {
                    count++
                    console.log("location判端密码")
                    locations++
                }
            }
        }
        console.log("zuihou COUNT:" + count)
        console.log("zuihou SJSON:" + sjson)
        console.log("zuihou LOCATIONS :" + locations)
        console.log("zuihou JOSNSS:" + josnss)
        if (count == 2 && (locations == 2 || josnss == 2)) {

            a++
            console.log("a:" + a)
            alert('登录成功！')
            localStorage.setItem("************", user.value)

            window.location.href = '../hospital/hospital.html'

        } else if (count == 1) {
            alert('密码或用户名不正确')
        } else {
            alert('该账号不存在')


        }

    }

}
console.log("Asdasd")
$.getJSON("JSON/userdata.json", function(e) {
    data = e
    console.log("Asdasd")
    manage()
    console.log(e)
        // alert("ok")

})